xen/cmdline: Fix buggy strncmp(s, LITERAL, ss - s) construct
authorAndrew Cooper <andrew.cooper3@citrix.com>
Fri, 1 Feb 2019 10:34:35 +0000 (11:34 +0100)
committerJan Beulich <jbeulich@suse.com>
Fri, 1 Feb 2019 10:34:35 +0000 (11:34 +0100)
commite202feb7131e66ed9186ad8766c9582502c98998
treed0c85039f860f06e84cf6700c824d36252167cd5
parent198672807ec6c6a1dee07841433a3064cb446a89
xen/cmdline: Fix buggy strncmp(s, LITERAL, ss - s) construct

When the command line parsing was updated to use const strings and no longer
tokenise with NUL characters, string matches could no longer be made with
strcmp().

Unfortunately, the replacement was buggy.  strncmp(s, "opt", ss - s) matches
"o", "op" and "opt" on the command line, as ss - s may be shorter than the
passed literal.  Furthermore, parse_bool() is affected by this, so substrings
such as "d", "e" and "o" are considered valid, with the latter being ambiguous
between "on" and "off".

Introduce a new strcmp-like function for the task, which looks for exact
string matches, but declares success when the NUL of the literal matches a
comma, colon or semicolon in the command line fragment.

No change to the intended parsing functionality, but fixes cases where a
partial string on the command line will inadvertently trigger options.

A few areas were more than just a trivial change:

 * parse_irq_vector_map_param() gained some style corrections.
 * parse_vpmu_params() was rewritten to use the normal list-of-options form,
   rather than just fixing up parse_vpmu_param() and leaving the parsing being
   hard to follow.
 * Instead of making the trivial fix of adding an explicit length check in
   parse_bool(), use the length to select which token to we search for, which
   is more efficient than the previous linear search over all possible tokens.

Signed-off-by: Andrew Cooper <andrew.cooper3@citrix.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
Acked-by: Julien Grall <julien.grall@arm.com>
master commit: 2ddf7e3e341df3ccf21613ff7ffd4b7693abe9e9
master date: 2019-01-15 12:58:34 +0000
xen/arch/x86/cpu/vpmu.c
xen/arch/x86/irq.c
xen/arch/x86/psr.c
xen/arch/x86/spec_ctrl.c
xen/arch/x86/x86_64/mmconfig-shared.c
xen/common/efi/boot.c
xen/common/kernel.c
xen/drivers/cpufreq/cpufreq.c
xen/drivers/passthrough/iommu.c
xen/drivers/passthrough/pci.c
xen/include/xen/lib.h